//
//  RBHomeAtyZoneShopView.m
//  zhongzhenglu
//
//  Created by XL on 2022/5/26.
//

#import "RBHomeAtyZoneShopView.h"
#import "RBDefine.h"
#import <YYCategories.h>
#import <Masonry.h>
#import "UIView+RBAdd.h"
#import "UIImageView+RBAdd.h"
#import "UIScrollView+RBAddHorizontal.h"
#import "RBShopDetailVC.h" //进店

@interface RBHomeAtyZoneShopView ()

@property(nonatomic, strong) UIScrollView *scrollView;

@end

@implementation RBHomeAtyZoneShopView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = UIColor.whiteColor;
    }
    return self;
}

- (void)clickShopAction:(UIGestureRecognizer *)ges {
    RBHomeAtyZoneModel *model = ges.view.rbExData;
    RBShopDetailVC *vc = RBShopDetailVC.new;
    vc.id = model.id;
    [self.viewController.navigationController pushViewController:vc animated:YES];
}

- (void)setData:(NSArray *)data
{
    _data = data;
    [self.scrollView h_rbSetContentHeight:[self.class suggestViewHeight]];
    for (NSInteger i = 0; i < data.count; i++)
    {
        RBHomeAtyZoneModel *model = data[i];
        UIView *cell = UIView.new;
        cell.rbExData = model;
        [cell rbAddTapGesWithTarget:self action:@selector(clickShopAction:)];
        CGFloat left =  i? [self.class padding]: 0;
        CGFloat width = [self.class imgW];
        [self addSubview:cell];
        [self.scrollView h_addView:cell withHeight:CGFLOAT_MIN width:width top:0 bottom:0 left:left right:CGFLOAT_MIN centerY:0];
        
        UIImageView *imgView = UIImageView.new;
        imgView.contentMode = UIViewContentModeScaleAspectFill;
        [imgView rbSetCornerRadius:Zoom(7.5)];
        [imgView setImageWithUrl:model.logo placeHolder:nil];
        [cell addSubview:imgView];
        [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.mas_equalTo(0);
            make.height.mas_equalTo([self.class imgH]);
        }];
        
        UILabel *textL = UILabel.new;
        textL.text = model.store_name;
        textL.font = [UIFont systemFontOfSize:Zoom(13)];
        textL.textColor = [UIColor colorWithHexString:@"333333"];
        textL.textAlignment = NSTextAlignmentCenter;
        [cell addSubview:textL];
        [textL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_equalTo(0);
        }];
    }
}

+ (CGFloat)margin
{
    return Zoom(18);
}

+ (CGFloat)padding
{
    return Zoom(11);
}

+ (CGFloat)imgW
{
    return Zoom(104);
}

+ (CGFloat)imgH
{
    return Zoom(104);
}

+ (CGFloat)suggestViewHeight
{
    return [self imgH] + Zoom(29);
}

- (UIScrollView *)scrollView
{
    if(!_scrollView)
    {
        self.scrollView = ({
            UIScrollView *view = UIScrollView.new;
            [self addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.bottom.mas_equalTo(0);
                make.left.mas_equalTo([self.class margin]);
                make.right.mas_equalTo(-[self.class margin]);
            }];
            view;
        });
    }
    return _scrollView;
}

@end
